<?php

namespace app\admin\controller;

use app\admin\model\Setting;
use think\facade\View;
use think\Request;

class SettingController extends Base
{

    /**
     * 网站信息首页
     *
     * @param Setting $setting
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index(Setting $setting)
    {

        $site_info = $setting->getOptionTags('site_info');

        View::assign('site_info', $site_info);
        return View::fetch();

    }

    /**
     * @param Setting $setting
     */
    public function add(Setting $setting)
    {

        if (\request()->isAjax()) {

            $param = \request()->param();

            [$res, $operation] = $setting->addOrUpdateOption($param);
            if ($res) {
                $this->success($operation);
            } else {
                $this->error($this->err_msg);
            }

        }

    }


}
